<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        height: 200px;
        background-color: white;
      }
    </style>
  </head>
  <body>
    <div id="box"><button id="btn">按钮<tton></div>
    <script>
      var div = document.querySelector("div");
      btn.onclick = function () {
        var r = parseInt(256 * Math.random());
        var g = parseInt(256 * Math.random());
        var b = parseInt(256 * Math.random());
        var randomcolor = "rgb(" + r + "," + g + "," + b + ")";
        console.log(randomcolor);
        div.style.cssText = "background:" + randomcolor;
      };
    </script>
  </body>
</html>